//
//  RHLocalConfigOptionVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/5/9.
//

#import "RHLocalConfigOptionVC.h"
#import "RHLocalParamSetVC.h"
#import "RHPolicySettingVC.h"
#import "RHDeviceParaSetVC.h"
#import "CBLECenterMnger.h"

@interface RHLocalConfigOptionVC ()
<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) NSArray *dataArr;

@property (nonatomic ,strong) UITableView *tableView;
@end

@implementation RHLocalConfigOptionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CFTabViewBgColor;
    self.navigationItem.title = @"运行配置".rh_localized;
    [self setupUI];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)setupUI{
    self.dataArr = @[@{CellIcon:@"device_set_policy",CellTitle:@"策略配置".rh_localized},@{CellIcon:@"device_set_para",CellTitle:@"参数配置".rh_localized}];
    kWeakSelf;
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.backgroundColor = CFTabViewBgColor;
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [self.view addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(10, 0, 0, 0));
    }];
    
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
    
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    kWeakSelf;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"optionCell"];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"optionCell"];
    }
    cell.contentView.backgroundColor = CFTabViewBgColor;
    UIView *bgView = kView;
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    [cell.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(5, 15, 5, 15));
    }];
    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:self.dataArr[indexPath.row][CellIcon]]];
    [bgView addSubview:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.width.height.offset(40);
        make.centerY.mas_offset(0);
    }];
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.textColor = kCOLOR_HEX(@"3F4443");
    titleLab.font = kSYSTEMFONT(15);
    titleLab.text = self.dataArr[indexPath.row][CellTitle];
    [bgView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(icon.mas_right).offset(5);
        make.centerY.mas_offset(0);
    }];
    
    UIImageView *indicator = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow"]];
    [bgView addSubview:indicator];
    [indicator mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.width.height.offset(15);
        make.centerY.mas_offset(0);
    }];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        [QMUITips showError:@"此设备类型不支持".rh_localized];
        return;
        NSLog(@"---->蓝牙设备类型:%@",[CBLECenterMnger shareMnger].curPheral.deviceType);
        if([[CBLECenterMnger shareMnger].curPheral.deviceType isEqualToString:@"HE_BAT"]||
           [[CBLECenterMnger shareMnger].curPheral.deviceType isEqualToString:@"HE_ALLINONE"]||
           [[CBLECenterMnger shareMnger].curPheral.deviceType isEqualToString:@"Battery"]||
              [[CBLECenterMnger shareMnger].curPheral.deviceType isEqualToString:@"All-In-One"]){
            
            [QMUITips showError:@"此设备类型不支持".rh_localized];
            return;
        }
        
        RHPolicySettingVC *policyVC = [[RHPolicySettingVC alloc]init];
        [self.navigationController pushViewController:policyVC animated:YES];
    }else{
     
        RHLocalParamSetVC *setVC = [[RHLocalParamSetVC alloc]init];
        [self.navigationController pushViewController:setVC animated:YES];
       
        
        
    }
    

}


@end
